package com.moly.thrift.person;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

public class PersonClient {

    public static void main(String[] args) {

        TSocket tSocket = new TSocket("localhost", 9090);
        try {
            tSocket.open();
            TProtocol protocol = new TBinaryProtocol(tSocket);
            PersonService.Client client = new PersonService.Client(protocol);

            client.say("你麻痹");
            System.out.println("-----------");
            Person person = client.getPersonById(2);
            System.out.println(person.toString());
            System.out.println("-----------");
            List<Person> list = client.getPersonsByAge(10);
            System.out.println(list.toString());
            list.forEach((p) -> {
                System.out.println(p.toString());
            });
            System.out.println("-----------");
            PersonMap personMap = client.getPersonByName("moly");
            System.out.println(personMap.toString());

            Map<String, String> map = client.test();
            System.out.println(map.toString());
            System.out.println("-----------");

            boolean exists = client.isExists(new Person().setAge(new Random().nextInt()));
            System.out.println("exists   " + exists);
            System.out.println("-----------");

            Set<Person> set = client.getAllPersonNoRepeated();
            System.out.println(set.toString());

        } catch (TTransportException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        }


    }
}
